<template>
  <div class="g_warp g_margin_auto detail-box">
    <div class="bottom">
      <div class="show">
        <div class="left">
          <div class="l">
            <img
              :src="$GLOBAL.imgPre + imgList[currentImgIndex].src"
            />
            <div class="img-box">
              <div
                v-for="(item, index) in imgList"
                :class="index === currentImgIndex ? 'img_no_mask' : ''"
                :key="index"
                @mouseenter="currentImgIndex = index"
              >
                <img :src="$GLOBAL.imgPre + item.src" alt="" />
                <div></div>
              </div>
            </div>
          </div>
          <div class="r">
            <div class="s-top">
              <div class="title">小狼抱枕</div>
              <div class="desc">松松软软的小狼，午间休息神器！</div>
              <div class="integral">2100[图片]</div>
            </div>
            <div class="s-mid">
              <div>
                <div>选择颜色</div>
                <ul>
                  <li>珊瑚粉</li>
                  <li>赤桃色</li>
                  <li>宝石红</li>
                  <li>浅绿色</li>
                  <li>典雅黑</li>
                  <li>墨绿色</li>
                  <li>香芋紫</li>
                </ul>
              </div>
              <div>
                <div>数量</div>
                <div>
                  <div>+</div>
                  <div>1</div>
                  <div>-</div>
                </div>
              </div>
              <div>
                <div>加入购物车</div>
                <div>立即购买</div>
              </div>
            </div>
            <div class="s-foot"></div>
          </div>
        </div>
        <div class="right"></div>
      </div>
      <div class="detail">商品详情</div>
      <button @click="$router.push(`/productDetail?id=${3}`)">
        另一个商品
      </button>
    </div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      imgList: [
        {
          src: "5f8984b3-cf46-42f5-b7e2-d1d12baa5b91.jpg",
          id: 1,
        },
        {
          src: "79297fd6-5393-4a12-91ed-5201f7f1b967.jpg",
          id: 2,
        },
        {
          src: "b8f6406f-63cd-4299-8698-6f8b22a9e9b3.jpg",
          id: 3,
        },
        {
          src: "8833d039-b098-4176-87c3-b80de9cfdc52.jpg",
          id: 4,
        },
      ],
      currentImgIndex: 0,
      currentImgSrc: '',
    };
  },
  created() {
    console.log("@详情页渲染");
    this.getQuery();
  },
  watch: {
    $route: {
      deep: true,
      handler() {
        this.getQuery();
      },
    },
  },
  methods: {
    getQuery() {
      const { query } = this.$route;
      if (query.id === undefined) {
        this.$store.dispatch('toast/showToast',{
          text: '商品id不能为空',
          type: 'error'
        })
      }
      console.log(`🚀 => created => query:`, query);
    },
  },
};
</script>

<style lang="less" scoped>
.show {
  margin: 21px 0 52px;
  display: flex;
}
.left {
  width: 970px;
  display: flex;

  .l > img {
    width: 460px;
    height: 440px;
  }
  .l > .img-box {
    margin-top: 21px;
    display: flex;
    justify-content: space-between;
  }
  .l > .img-box img {
    width: 100px;
    height: 100px;
  }
  .l > .img-box > div {
    position: relative;
  }
  .l > .img-box > div::after {
    content: "";
    position: absolute;
    width: 100px;
    height: 100px;
    top: 0;
    left: 0;
    background: rgba(#fff, 0.7);
    z-index: 10;
  }

  .l > .img-box > div.img_no_mask::after {
    background: rgba(#fff, 0);
  }
  .r {
    width: 510px;
    height: 440px;
    border-right: 1px solid #eee;
  }
  .r .s-top {
    margin-left: 31px;
    margin-right: 50px;
    border-bottom: 1px solid #eee;
    text-align: left;
    .title {
      margin-bottom: 15px;
      font-size: 28px;
      font-weight: 400;
      color: #000000;
    }
    .desc {
      margin-bottom: 26px;
      font-size: 14px;
      font-weight: 300;
      color: #999999;
    }
    .integral {
      font-size: 28px;
      font-weight: bold;
      color: #fd604d;
      margin-bottom: 23px;
    }
  }
}
</style>

